package com.tan.kotlintest.helper

import android.content.Context
import com.tan.kotlintest.bean.ChatUserInfo

/*
 * Copyright (C) 2018 重庆一聊高科技有限公司
 * 版权所有
 *
 * 功能描述：SharedPreference帮助类
 * 作者：txj
 * 创建时间：2018/6/72
 *
 * 修改人：
 * 修改描述：
 * 修改日期
 */
object SharedPreferenceHelper {

    //登录相关
    private const val KEY_CONFIG_LOGIN = "login"
    private const val PHONE = "phone"
    private const val GENDER = "t_sex"
    private const val USER_ID = "t_id"
    private const val IS_VIP = "t_is_vip"
    private const val T_ROLE = "t_role"
    private const val NICK_NAME = "nickName"
    private const val HEAD_URL = "headUrl"//头像

    /**
     * 获取登录的账户信息
     */
    fun getAccountInfo(context: Context): ChatUserInfo {
        val sp = context.getSharedPreferences(KEY_CONFIG_LOGIN, Context.MODE_PRIVATE)
        val chatUserInfo = ChatUserInfo()
        chatUserInfo.t_id = sp.getInt(USER_ID, 0)
        chatUserInfo.phone = sp.getString(PHONE, "")
        chatUserInfo.t_is_vip = sp.getInt(IS_VIP, 1)
        chatUserInfo.t_sex = sp.getInt(GENDER, 2)
        chatUserInfo.t_role = sp.getInt(T_ROLE, 2)
        chatUserInfo.nickName = sp.getString(NICK_NAME, "")
        chatUserInfo.headUrl = sp.getString(HEAD_URL, "")
        return chatUserInfo
    }

}